import os
from XEdu.hub import Workflow as wf
import csv
import cv2
import numpy as np
body = wf(task='pose_body26')

# 要遍历的文件夹路径
folder_path = 'C:/Users/czeva/Desktop/20240527/no'
with open('C:/Users/czeva/Desktop/20240527/no.csv', 'w', newline='') as csvfile:
            writer = csv.writer(csvfile)
            # 遍历文件夹中的所有文件
            for filename in os.listdir(folder_path):
    # 获取文件的完整路径
                file_path = os.path.join(folder_path, filename)
    
    # 检查文件是否是图片文件（假设以.jpg、.png、.jpeg为图片扩展名）
                if file_path.endswith(('.jpg', '.jpeg', '.png')):
        # 在这里，你可以将 file_path 加入你的程序中进行处理
                        keypoints,img_with_keypoints = body.inference(data=file_path,img_type='pil') # 进行模型推理
                        img=cv2.imread(file_path)
                        height, width, channels = img.shape
                        div = np.array([width,height])
                        keypoints = keypoints / div
                        print(file_path)
        
                        writer.writerow([coord for point in keypoints for coord in point])
